﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MetroStyle
{
    internal class PublicCode
    {
        /// <summary>
        /// 未设置父窗口时容错，自己去找，但是手动设置窗口效率会好很多。
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        internal static Form GetMainForm(Control c)
        {
            try
            {
                if (c.GetType() == typeof(Form))
                    return (Form)c;
                var p = (Form)c.Parent;
                return p;
            }
            catch {
                if (c.Parent != null)
                    return GetMainForm(c.Parent);
                return null;
            }
        }
    }
}
